package com.supermap.search.utils;

import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;

import com.supermap.search.javabean.XyIDComplicated;
import com.supermap.search.javabean.XyIDSimple;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by wyw on 2017/3/17.
 */

public class DbUtils {



    public static List<XyIDSimple> getXyIDSimple(){

        List<XyIDSimple> list = new ArrayList();
        String fileName = "/sdcard/shenzhen/db/guanxian.db";
        SQLiteDatabase database = SQLiteDatabase.openDatabase(fileName, null, SQLiteDatabase.OPEN_READONLY);
        Cursor cursor = database.query("Sheet1",null,null,null,null,null,null);
        while (cursor.moveToNext()){
            XyIDSimple xyIDSimple = new XyIDSimple();
            xyIDSimple.setX(cursor.getDouble(cursor.getColumnIndex("SmX")));
            xyIDSimple.setY(cursor.getDouble(cursor.getColumnIndex("SmY")));
            xyIDSimple.setID(cursor.getDouble(cursor.getColumnIndex("管线id")));
            list.add(xyIDSimple);
        }
        cursor.close();
        database.close();
        return list;
    }

    public static XyIDComplicated getXyIDComplicated(String id){
        XyIDComplicated xyIDComplicated = null;
        String fileName = "/sdcard/shenzhen/db/guanxian.db";
        SQLiteDatabase database = SQLiteDatabase.openDatabase(fileName, null, SQLiteDatabase.OPEN_READONLY);
        Cursor cursor = database.rawQuery("select * from Sheet2 where SmID = ?", new String[]{id});
        if(cursor!=null&&cursor.moveToNext()){
            xyIDComplicated = new XyIDComplicated();
            xyIDComplicated.setSmID(cursor.getDouble(cursor.getColumnIndex("SmID")));
            xyIDComplicated.setADDRESS(cursor.getString(cursor.getColumnIndex("ADDRESS")));
            xyIDComplicated.setLAYTYPE(cursor.getString(cursor.getColumnIndex("LAYTYPE")));
            xyIDComplicated.setMATERIAL(cursor.getString(cursor.getColumnIndex("MATERIAL")));
            xyIDComplicated.setSmLength(cursor.getDouble(cursor.getColumnIndex("SmLength")));
            cursor.close();
        }
        database.close();
        return xyIDComplicated;
    }

}
